<template>
	<view class="beijingse" v-if="pageShow">
		<view class="mainpadding">
			<view class="dingwei flexcenter margin_top" @click="uploadImg(1,avatar,avatar_text)">
				<image  class="touxiang" :src="avatar_text!=''?avatar_text:'@/static/image/system/weidenglu.png'" mode=""></image>
				<image class="xianj" src="../static/images/system/xj.png" mode=""></image>
			</view>
		</view>
		<view class="mainpadding ffffff margin_top1 flexbetween">
			<view class="sanshier fonweight">昵称</view>
			<input type="text" placeholder="请输入" style="text-align: right;" class="textright" v-model="nickname">
		</view>
		<view class="mainpadding ffffff margin_top flexbetween">
			<view class="sanshier fonweight">姓名</view>
			<input type="text" placeholder="请输入真实姓名" style="text-align: right;" class="textright" v-model="username">
		</view>
		<view class="mainpadding ffffff margin_top flexbetween">
			<view class="sanshier fonweight">手机号</view>
			<input type="text" placeholder="请输入" style="text-align: right;" class="textright" disabled="" v-model="mobile">
		</view>
		<view class="mainpadding ffffff margin_top flexbetween" @click="jumper('/pages_wode/cheliangxx')">
			<view class="sanshier fonweight">车辆信息</view>
			<view class="flexright">
				<input type="text" placeholder="请编辑车辆信息" style="text-align: right;" disabled="" class="textright" >
				<u-icon name="arrow-right" color="#C8C8C8"></u-icon>
			</view>
		</view>
		<view class="mainpadding ffffff margin_top flexbetween" @click="messageTime.timeShow=true">
			<view class="sanshier fonweight">出生年月</view>
			<view class="flexright">
				<input type="text" placeholder="请选择出生年月" disabled="" style="text-align: right;" class="textright" v-model="birthday">
				<u-icon name="arrow-right" color="#C8C8C8"></u-icon>
			</view>
		</view>
		<view class="mainpadding ffffff margin_top flexbetween">
			<view class="sanshier fonweight">职业</view>
			<input class="textright" placeholder="请输入职业" type="text" v-model="job"/>
		</view>
		<view class="mainpadding ffffff margin_top">
			<view class="sanshier fonweight">兴趣爱好</view>
			<textarea class="margin_top textarea" placeholder="请输入兴趣爱好" v-model="bio"></textarea>
		</view>
		<!--  -->
		<view class="gudingdb mainpadding" @click="submit()">
			<view class="bigbtn">保存</view>
		</view>
		<timePicker :messageTime="messageTime" @timeConfirm="timeConfirm"></timePicker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				messageTime:{
					timeShow:false,
					title:"选择出生年月",
					mode:"date",//date日期，datetime年月日时分秒，time时间，year-month年月
					minDate:Number(new Date("1900-01-01"))//最小时间
				},
				avatar:"",
				avatar_text:"",
				nickname:"",
				username:"",
				birthday:"",
				job:"",
				bio:"",
				mobile:"",
				pageShow:false,
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			submit(){
				httpRequest.request('/api/user/profile', 'GET', {
					nickname:this.nickname,
					avatar:this.avatar,
					nickname:this.nickname,
					birthday:this.birthday || "",
					job:this.job,
					bio:this.bio,
					username:this.username
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg);
					setTimeout(()=>{
						uni.navigateBack(1)
					},1000)
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			init() {
				httpRequest.request('/api/user/index', 'GET', {}, false, false, true).then(res => {
					this.avatar = res.data.avatar
					this.avatar_text = res.data.avatar_text
					this.nickname = res.data.nickname
					this.mobile = res.data.mobile
					this.birthday = res.data.birthday
					this.job = res.data.job
					this.bio = res.data.bio
					this.username = res.data.username
					this.pageShow = true
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			uploadImg(value, upImgs,upImgs_text) {
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs,upImgs_text)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs,upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			uploadImageService(url, upImg,upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					this.avatar = res.url;
					this.avatar_text = image_item
					
				}).catch(err => {});
			},
			timeConfirm(e){
				this.birthday = e
			},
			jumper(url) {
				uni.navigateTo({
					url: url
				})
			},
			confirm() {
				this.show = false;
				// 将存储的数据改为空达到退出登录的效果
				uni.setStorageSync('token', "");
				httpRequest.toast("退出登录成功")
				setTimeout(() => {
					uni.redirectTo({
						url: '/pages/login/login'
					})
				}, 1000)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.textarea{
		height: 100rpx;
	}
	.xianj {
		width: 46.13rpx;
		height: 46.13rpx;
		position: absolute;
		bottom: 0;
		right: 282rpx;
	}

	.touxiang {
		width: 182rpx;
		height: 182rpx;
		border-radius: 50%;
	}
</style>